﻿using FS.Common.DotNetBean;
using FS.Common.DotNetCode;
using FS.Common.DotNetJson;
using FS.Common.DotNetUI;
using FS.Business;
using System;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Text;

namespace FS.Web.BLL.Visa_Base
{
    /// <summary>
    /// Summary description for _baseD:\Person\Project\C#\签证查询系统\FS.MFC\FS.Web\BLL\Visa_Base\Base_CertCityList.aspx
    /// </summary>
    public class _base : IHttpHandler, IRequiresSessionState
    {
        private visa_dao _visa = new visa_dao();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1.0);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            string Action = context.Request["action"];
            string cityarea = context.Request["cityarea"];
            string cityid = context.Request["cityid"];
            string certtype = context.Request["certtype"];
            string trusttype = context.Request["trusttype"];
            string trustid = context.Request["trust_id"];
            string supplyid = context.Request["supplyid"];            
           
            string text = Action;
            if (text != null)
            {
                if (text == "getcitybyarea") //根据区域获取城市列表
                {
                    DataTable dt = _visa.GetSelect_CityInfoByCityArea(cityarea);
                    string sb = JsonHelper.DataTableToJson(dt, "MENU");

                    context.Response.Write(sb.ToString());
                    context.Response.End();
                }               
                else if (text == "getcerttype") //根据城市获取签证类型
                {
                    DataTable dt = _visa.GetSelect_CertTypeInfoByCityID(cityid);
                    string sb = JsonHelper.DataTableToJson(dt, "MENU");

                    context.Response.Write(sb.ToString());
                    context.Response.End();
                }               
                else if (text == "GetSupplybycitycert")    //获取报价的供应商
                {
                     DataTable dt = _visa.GetSelect_SupplyInfoByCityIDAndCertType(cityid, certtype);

                     string sb = JsonHelper.DataTableToJson(dt, "MENU");
                     context.Response.Write(sb.ToString());
                     context.Response.End();
                }
                else if (text == "gettrustinfo")    //根据委托方信息
                {
                    string strMenus = "";
                    DataTable dt = _visa.GetSelect_trustInfoBytrustid(trustid);
                    if (dt.Rows.Count > 0)
                    {
                        strMenus = dt.Rows[0]["type_trust"].ToString() + "@" +
                            dt.Rows[0]["type_price"].ToString() + "@" +
                            dt.Rows[0]["trust_contactnumber"].ToString() + "@" +
                            dt.Rows[0]["trust_contactuser"].ToString()+ "@" +
                            dt.Rows[0]["keycode"].ToString()+"@"+
                            dt.Rows[0]["trust_user"].ToString();
                    }
                    context.Response.Write(strMenus);
                    context.Response.End();
                }                 
                else if (text == "GetPriceFromCityCert")    //根据国家签证报价
                {
                    string ls_price = _visa.Ajax_GetPriceFromCityCert(cityid, certtype, trusttype);
                    context.Response.Write(ls_price);
                    context.Response.End();
                }
                else if (text == "GetPriceFromSupply")    //根据供应商签证报价
                {
                    string ls_price = _visa.Ajax_GetPriceFromSupply(cityid, certtype, supplyid);

                    context.Response.Write(ls_price);
                    context.Response.End();
                }                
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}